package com.wf.ew.system.controller;

import com.wf.ew.common.BaseController;
import com.wf.ew.common.JsonResult;
import com.wf.ew.common.PageResult;
import com.wf.ew.system.model.Company;
import com.wf.ew.system.service.CompanyService;
import net.sf.json.JSONArray;
import org.apache.poi.ss.formula.functions.T;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 *
 * controller
 * @author : Doman
 * @date : 2019-08-17 15:38:50
 * @version ：1.0
 */

@Controller
@RequestMapping("/system/company")
public class CompanyController extends BaseController {

	@Autowired
	private CompanyService companyService;
	
	/**
	 * 页面
	 **/
	@RequiresPermissions("company:view")
	@RequestMapping()
	public String company() {
		return "system/company.html";
	}

	/**
	 * 页面
	 **/
	@RequestMapping(value = "/companySel")
	public String companySel(Model model, Company company) {
		model.addAttribute("company",company);
		return "system/companySel.html";
	}


	/**
	 * 查询列表
	 */
	@RequiresPermissions("company:view")
	@RequestMapping(value = "/list", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String list(PageResult<T> page, Company company){
		return companyService.list(page, company,getLoginUser());
	}
	
	/**
	 * 查询列表
	 */
	@RequiresPermissions("company:view")
	@RequestMapping(value = "/ajaxList", produces = {"text/html;charset=UTF-8;"})
	@ResponseBody
	public String ajaxList(Company company){
		return JSONArray.fromObject(companyService.list(company,getLoginUser())).toString();
	}

	/**
	 * 新增
	 **/
	@RequiresPermissions("company:add")
	@ResponseBody
	@RequestMapping("/add")
	public JsonResult add(Model model, Company company) {
		return companyService.add(company, getLoginUser());
	}

	/**
	 * 修改
	 **/
	@RequiresPermissions("company:update")
	@ResponseBody
	@RequestMapping("/update")
	public JsonResult update(Model model, Company company) {
		return companyService.update(company, getLoginUser());
	}

	/**
	 * 批量删除
	 **/
	@RequiresPermissions("company:delete")
	@RequestMapping("/delete")
	@ResponseBody
	public JsonResult delete(Company company ) {
		return companyService.delete(company, getLoginUser());
	}

}
